package com.prs.crm.action.hr;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.annotation.Clew;
import com.prs.crm.domain.hr.SalaryFloatItem;
import com.prs.crm.service.hr.SalaryFloatItemService;

public class SalaryFloatItemAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private SalaryFloatItem salaryFloatItem;
	private SalaryFloatItemService salaryFloatItemService;
	private PaginationSupport pagination;
	private Integer[] ids;

	@Action("listSalaryFloatItem")
	public String execute() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				SalaryFloatItem.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getSalaryFloatItemService().listByPage(
				criteria, pagination));
		return SUCCESS;
	}

	@Action("editSalaryFloatItem")
	public String edit() {
		return SUCCESS;
	}

	@Clew(results = { "success" })
	@Action(value = "saveSalaryFloatItem", results = {
			@Result(name = "success", type = "redirect", location = "listSalaryFloatItem"),
			@Result(name = "error", type = "chain", location = "editSalaryFloatItem") })
	public String save() {
		if (salaryFloatItem.getName() == null
				|| salaryFloatItem.getName().trim().equals("")) {
			addActionError("名称不能为空");
			return ERROR;
		}
		if (salaryFloatItem.getType() == null) {
			addActionError("类型不能为空");
			return ERROR;
		}
		this.setPrompt("提交薪酬浮动项目成功");
		this.getSalaryFloatItemService().save(salaryFloatItem);
		return SUCCESS;
	}

	@Action(value = "removeSalaryFloatItem", results = { @Result(name = "success", type = "redirect", location = "listSalaryFloatItem") })
	public String remove() {
		this.getSalaryFloatItemService().batchRemove(ids);
		return SUCCESS;
	}

	public SalaryFloatItem getSalaryFloatItem() {
		return salaryFloatItem;
	}

	public void setSalaryFloatItem(SalaryFloatItem salaryFloatItem) {
		this.salaryFloatItem = salaryFloatItem;
	}

	public SalaryFloatItemService getSalaryFloatItemService() {
		return salaryFloatItemService;
	}

	public void setSalaryFloatItemService(
			SalaryFloatItemService salaryFloatItemService) {
		this.salaryFloatItemService = salaryFloatItemService;
	}

	public PaginationSupport getPagination() {
		return pagination;
	}

	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}

	public Integer[] getIds() {
		return ids;
	}

	public void setIds(Integer[] ids) {
		this.ids = ids;
	}

}
